<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>


    <!--{include file='comm/header.tpl'}-->
    <title>下午茶套餐配置</title>
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--引用div做成的下拉框效果样式-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/department_select.css" type="text/css" media="screen" />

    <!--引用div做成的下拉框效果js-->
    <script language="JavaScript" src="/quanliadmin/docroot/js/department_select.js" type="text/javascript"></script>
</head>

<body>

<style>
    .imageSites{
        position: absolute;
        left:275px;
        top:8px;
    }
    .search_option_drop{
        width:300px;
    }

</style>


<div class="container">

    <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                            <span>
                               销售时间：<input type="text"  class="form-control input-sm" name="send_date" id="send_date" readonly="readonly" style="width:150px;"/>
                            </span>
                            <span>
                                <button type="button" class="btn btn-primary" id="searchBtn" onclick="basicSetting.search();">查询</button>
                            </span>
                            <span>
                                <button type="button" class="btn btn-warning" id="clearBtn" onclick="basicSetting.clearUp();" >重置</button>
                            </span>
                    </form>
                </div>
            </div>
            <div id="pop" style="display: none;height: 500px;">
                <form id="categoryForm" class="form-horizontal" role="form" onsubmit="return false;">
                    <input type="hidden" id="itemCategoryID" name="itemCategoryID" value=""/>
                    <div class="form-group" >
                        <div class="col-sm-9" id="info">

                            <div style="width: 600px;margin: 20px 20px;">
                                <div id="datepicker" class=" ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" style="height: 400px;float: left;border: 1px;margin-right: 20px;width: 250px"></div>

                                    日期： <input type="hidden" name="old_sale_date" id="old_sale_date" value="" class="form-control input-sm" style="width: 150px;"readonly="readonly"><input type="text" id="sale_date" name="sale_date" class="form-control input-sm" style="width: 150px;"readonly="readonly">

                                    套餐一：<select name="package_id[]" id='packageOne'class="form-control input-sm" style="width: 150px;"  >
                                        <option value="">请选择</option>
                                        <!--{foreach from=$dunchinfo item=pic key=k}-->
                                        <option value="<!--{$pic.package_id}-->"><!--{$pic.package_name}--></option>
                                        <!--{/foreach}-->
                                    </select>
                                    套餐一数量：<input type="text" name="num[]" id="numOne" value="" class="form-control input-sm" style="width: 150px;">

                                    套餐二：<select name="package_id[]"  id='packageTwo' class="form-control input-sm" style="width: 150px;"  >
                                        <option value="">请选择</option>
                                        <!--{foreach from=$dunchinfo item=pic key=k}-->
                                        <option value="<!--{$pic.package_id}-->"><!--{$pic.package_name}--></option>
                                        <!--{/foreach}-->
                                    </select>
                                套餐二数量：<input type="text" name="num[]" id="numTwo" value="" class="form-control input-sm" style="width: 150px;">
                                        套餐三：<select name="package_id[]" id='packageThree' class="form-control input-sm" style="width: 150px;"  >
                                        <option value="">请选择</option>
                                        <!--{foreach from=$dunchinfo item=pic key=k}-->
                                        <option value="<!--{$pic.package_id}-->"><!--{$pic.package_name}--></option>
                                        <!--{/foreach}-->
                                    </select>
                                套餐三数量：<input type="text" name="num[]" id="numThree" value="" class="form-control input-sm" style="width: 150px;">
                                权益数量： <input type="text" name="right_num" id="right_num" value="" class="form-control input-sm" style="width: 150px;">


                            </div>

                        </div>
                    </div>




                </form>
            </div>
            <table id="flex" style="display:none"></table>
        </div>

</div>
<script type="text/javascript">
$("#send_date").datepicker();
$("#flex").flexigrid({
    url:"/invokingAjax-backend/dunch/dunch.ajax?operFlg=7",
    dataType: "json",
    colModel : [
        {display: "操作", width : 100, align: "center"},
        {display: "序号", width : 100, align: "center"},
        {display: "销售时间", width : 140,align:"left"},
        {display: "销售套餐", width : 140,align:"left"},
        {display: "套餐数量", width : 140,align:"left"},
        {display: "权益数量", width : 140,align:"left"},
        {display: "已抢数量", width : 140,align:"left"}

    ],
    buttons : [
        {name: "添加", bclass: "add", onpress : "basicSetting.add"}
    ],
    sortname: "sale_id",
    sortorder: "asc",
    usepager: true,
    rp: 10,
    useRp: true,
    showTableToggleBtn: true,
    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    }
});

var basicSetting = {

    itemCategoryID:'',
    itemID:'',
    selected:'',
    //搜索
    search: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt}).flexReload();
    },
    //添加分类信息
    add: function() {
        E.popup.open({
            id:"pop",                  //获取id为"pop"元素内的HTML
            title:"添加下午茶信息",       //弹出层标题
            css: "width:560px;hight:550px;",   //设置弹出层样式
            btnName: "保存",        //执行“确定”操作的按钮名称
            btnCall:"basicSetting.checkInfo();"  //点击确定后执行的方法
        });
        $("#datepicker").datepicker({
            onSelect: function(dateText,inst){
                $("#sale_date").val(dateText);
            }
        });
        $("#datepicker").children("div").attr('style','width:250px;display:block');




    },

    //删除选项信息
    delx:function(){
        alert(2222);
    },
    //验证分类信息
    checkInfo:function(){
        var data = E.getFormValues("categoryForm");
        var error_msg = "";


        if (data.sale_date == ''){
            error_msg += '日期不能为空<br/>';
        }
       if(data.package_id[0]=='' || data.package_id[1]=='' || data.package_id[2]==''){
           error_msg += '套餐不能为空<br/>';
       }
        if(data.num[0]=='' || data.num[1]=='' || data.num[2]==''){
            error_msg += '数量不能为空<br/>';
        }
        if (data.right_num == ''){
            error_msg += '权益数量不能为空<br/>';
        }

        if (error_msg != ""){
           E.alert(error_msg);
        }else{
        E.confirm('您确认添加下午茶配置信息吗?', "basicSetting.addExe");
        }
    },
    //执行 添加
    addExe: function() {
        //弹出遮罩层
        E.loadding.open("执行中……");
        //获取表单参数
        var data = E.getFormValues('categoryForm');
        jquery_ajax(6,data,basicSetting.callback);
        //关闭弹出层
        E.popup.close();
        //关闭遮罩层
        E.loadding.close();
    },
    /**
     * 编辑分类
     */
    edit: function( sale_date ) {

        E.loadding.open("正在查询，请稍后...");
        E.ajax_post({
            url:"/invokingAjax-backend/dunch/dunch.ajax?operFlg=8",
            data:{sale_date:sale_date},
            call:"basicSetting.editResult"
        });
        //显示弹出层
        E.popup.open({
            id:"pop",
            title: "修改分类",
            css: "width:550px;",
            btnName: "确认修改",
            btnCall:"basicSetting.editCheck();"
        });

        $("#datepicker").datepicker({
            onSelect: function(dateText,inst){
                $("#sale_date").val(dateText);

            }
        });
        $("#old_sale_date").val(sale_date);
        $("#old_sale_date").attr('type','text');
        $("#sale_date").attr('type','hidden');
        $("#datepicker").children("div").attr('style','width:250px;display:block');


    },
    //查询结果
    editResult:function(o){

        E.loadding.close();
        if( o.code != 200 ){
            E.alert( o.message );
            return false;
        }
        var data = o.data;
        $('#sale_date').val(data[0]['sale_date']);
        $('#packageOne').val(data[0]['package_id']);
        $('#packageTwo').val(data[1]['package_id']);
        $('#packageThree').val(data[2]['package_id']);
        $('#numOne').val(data[0]['package_num']);
        $('#numTwo').val(data[1]['package_num']);
        $('#numThree').val(data[2]['package_num']);
        $('#right_num').val(data[2]['right_num']);




    },
    //修改验证
    editCheck:function(){
        var data = E.getFormValues("categoryForm");
        var error_msg = '';
        if (data.sale_date == ''){
            error_msg += '日期不能为空<br/>';
        }
        if(data.package_id[0]=='' || data.package_id[1]=='' || data.package_id[2]==''){
            error_msg += '套餐不能为空<br/>';
        }
        if(data.num[0]=='' || data.num[1]=='' || data.num[2]==''){
            error_msg += '套餐数量不能为空<br/>';
        }
        if (error_msg != ""){
            E.alert(error_msg);
        }else{
        E.confirm('您确认修改分类吗?', "basicSetting.editExe");
        }

    },
    //编辑执行
    editExe:function(){
        //弹出遮罩层
        E.loadding.open("正在执行，请稍后...");
        //获取表单参数
        var data = E.getFormValues('categoryForm');
        jquery_ajax(9,data,basicSetting.callback);
        //关闭弹出层
        E.popup.close();
        //关闭遮罩层
        E.loadding.close();
    },


    //删除选项分类
    delPackge:function( sale_id ){
        //this.selected = $( thisObj ).parents("tr");
        this.sale_id = sale_id;
        E.confirm('您确认删除该分类选项吗?','basicSetting.delExe');
    },

    delExe:function(){
        $.ajax({
            type: "POST",
            url: "/invokingAjax-backend/dunch/dunch.ajax?operFlg=10",
            dataType: "JSON",
            data:{
                sale_id: this.sale_id
            },
            success: function(result_obj){
                if (result_obj.code == 200) {
                    E.alert(result_obj.message, 2);
                    $("#flex").flexReload();

                }
                else {
                    E.alert(result_obj.message);
                }
            }
        });
    },

    //回调函数
    callback: function( obj ) {
        E.loadding.close();
        E.popup.close();
        if( obj.code == 200 ){
            E.alert( obj.message , 2 , 'basicSetting.load');
        }else{
            E.alert(obj.message);
        }
    },
    load: function() {
        $("#flex").flexReload();
    },
    //重置分类名称
    clearUp:function() {
        $("#send_date").val('');
        basicSetting.load();
    }
};
function jquery_ajax(flg,data,func){
    $.ajax({
        type: "post",
        url: "/invokingAjax-backend/dunch/dunch.ajax?operFlg="+flg,
        dataType: "json",
        data: data,
        success: function( result_obj ) {
            func(result_obj);
        },
        error : function(msg){
            alert('网络不给力，请重新尝试...');
        }
    });
}


//绑定上传图片
KindEditor.ready(function(K) {

    var kindEditor_upload = K.editor({
        allowFileManager : true,
        uploadJson: '/framework/kindeditor/php/upload_json.php?act=system'
    });

    $(document).on('click', '#update_logo', function() {

        kindEditor_upload.loadPlugin('image', function() {
            kindEditor_upload.plugin.imageDialog({
                showRemote : false,
                clickFn : function(url) {

                    $('#logo_img_box').html('<img style="width:110px;height: 110px;" src="' + url + '"> <a href="javascript: void(0);" id="del_log_img">删除</a>').show();
                    $('#itemName').val(url);
                    kindEditor_upload.hideDialog();

                }
            });
        });

    });

    $(document).on('click', '#del_log_img', function() {
        $('#logo_img_box').html('').hide();
        $('#itemName').val('');
    });

});

</script>
</body>
</html>